﻿using System;
using System.Net.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Dispatcher;
using FlitBit.Core;

namespace FlitBit.Dto.Mvc.WebApi
{
    public class WebApiDtoHttpControllerActivator : IHttpControllerActivator
    {
	    public IHttpController Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor,
		    Type controllerType)
	    {
		    var currentFactory = FactoryProvider.Factory;

		    if (currentFactory.CanConstruct(controllerType))
		    {
			    return currentFactory.CreateInstance(controllerType) as IHttpController;
		    }
		    return null;
	    }

    }
}